/**
 * Created by Administrator on 2017/4/6.
 */
var og=document.getElementById('canvas');
var ogc=og.getContext('2d');
var tip= document.getElementById("tip");
window.onload=function () {

    /*取消鼠标事件*/
    og.oncontextmenu = function(){
        return false;
    };

    //game1_round1();
    preToChoose();

};
/*初始加载方法*/
function preToChoose() {
    //window.console.log("开始执行prechoose方法");
    drawLine();
    var flicker=setInterval(light,10);
    var r=255,t=0;

    /*绘制闪电标志 一闪一闪*/
    function light() {
        ogc.beginPath();
        ogc.moveTo(550,100);
        ogc.lineTo(380,335);
        ogc.lineTo(500,335);
        ogc.lineTo(450,500);
        ogc.lineTo(620,265);
        ogc.lineTo(500,265);
        ogc.closePath();
        ogc.fillStyle="rgb("+r+","+r+","+r+")";
        t==0&&r--;
        if(r==0)t=1;
        if(r==200)t=0;
        t==1&&r++;
        ogc.fill();
    }
    tip.onclick=function () {
        tip.innerHTML=" ";
    };
    document.body.onkeydown=function () {
        ogc.clearRect(0,0,og.width,og.height);
        clearInterval(flicker);
        og.onmousedown=null;
        tip.innerHTML="w/s选择游戏，按enter开始游戏";
        tip.style.color="#000";
        tip.style.top="0";
        og.style.cursor="none";
        choose();
    };
    //window.console.log("document.onkeydown将触发离开prechoose方法，执行choose方法");
}
/*画线条的方法*/
function drawLine() {
    og.onmousedown=function (ev) {
        ev= ev || window.event;
        ogc.moveTo(ev.clientX-og.offsetLeft,ev.clientY-og.offsetTop);
        document.onmousemove=function (ev) {
            ogc.lineTo(ev.pageX-og.offsetLeft-(og.offsetWidth-1000)/2,ev.pageY-og.offsetTop-(og.offsetWidth-1000)/2);
            ogc.stroke();
        };
        document.onmouseup=function () {
            document.onmousemove=null;
            document.onmouseup=null;
        }
    };
}

